package com.zzw.springboot.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zzw.springboot.entity.Course;
import com.zzw.springboot.entity.StudentCourse;
import com.zzw.springboot.mapper.StudentCourseMapper;
import com.zzw.springboot.service.ICourseService;
import com.zzw.springboot.service.IStudentCourseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 学生选课 服务实现类
 * </p>
 *
 * @author zzw
 * @since 2022-06-11 08:35:13
 */
@Service
public class StudentCourseServiceImpl extends ServiceImpl<StudentCourseMapper, StudentCourse> implements IStudentCourseService {

    @Autowired
    private ICourseService courseService;
    @Override
    public List<Course> stuCourse(Integer id) {
        List<StudentCourse> studentCourses = list(Wrappers.<StudentCourse>lambdaQuery()
                .eq(StudentCourse::getStudentId, id));

        return studentCourses.stream().map(studentCourse -> courseService.getOne(Wrappers.<Course>lambdaQuery()
                .eq(Course::getId, studentCourse.getCourseId()))).collect(Collectors.toList());
    }
}
